home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-04-21 | 12.0 KB | 462 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: TextFrame.cpp
- // Release Version: $ 1.0d1 $
- //
- // Author: Anthone Burbidge
- // Creation Date: 3/28/94
- //
- // Copyright: © 1993, 1994 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- // ----- Macintosh Includes -----
-
- #ifndef __FIXMATH__
- #include <FixMath.h>
- #endif
-
- #ifndef mathRoutinesIncludes
- #include <Math Routines.h>
- #endif
-
- #ifndef FWUTIL_H
- #include <FWUtil.h>
- #endif
-
- #ifndef FWRECT_H
- #include <FWRect.h>
- #endif
-
-
- // ----- OpenDoc Includes -----
-
- #ifndef _SHAPE_
- #include <Shape.h>
- #endif
-
- #ifndef _WINDOW_
- #include <Window.h>
- #endif
-
- #ifndef _MENUBAR_
- #include <MenuBar.h>
- #endif
-
- #ifndef _XMPSESSM_
- #include <XMPSessM.h>
- #endif
-
- #ifndef _DISPTCH_
- #include <Disptch.h>
- #endif
-
- #ifndef _INFO_
- #include <Info.h>
- #endif
-
- // ----- Textension Includes -----
-
- #ifndef _Textension_
- #include "Textension.h"
- #endif
-
- #ifndef _TextensionCommand_
- #include "TextensionCommand.h"
- #endif
-
- // ----- TextPart Includes -----
-
- #ifndef _TEXTUTIL_
- #include "TextUtil.h"
- #endif
-
- #ifndef _TEXTFACET_
- #include "TextFacet.h"
- #endif
-
- #ifndef _TEXTFRAME_
- #include "TextFrame.h"
- #endif
-
- #ifndef _TEXTPART_
- #include "TextPart.h"
- #endif
-
- #ifndef _STYLEINFO_
- #include "StyleInfo.h"
- #endif
-
- #ifndef _ODTEXT_
- #include "ODText.h"
- #endif
-
- #pragma segment TextPartSegment
-
-
- //========================================================================================
- // CLASS CTextFrame
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::CTextFrame
- //----------------------------------------------------------------------------------------
-
- CTextFrame::CTextFrame() :
- FW_CEmbeddingFrame(),
- fTextPart(NULL),
- fRulerFrame(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::ITextFrame
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::ITextFrame(XMPFrame* xmpFrame, CTextPart* textPart)
- {
- InitEmbeddingFrame(xmpFrame, textPart);
-
- // ----- By default we put all of them
- AddToFocusSet(textPart->GetKeyFocusToken());
- AddToFocusSet(textPart->GetMenuFocusToken());
- AddToFocusSet(textPart->GetSelectionFocusToken());
-
- // ----- Register for idle time
- textPart->GetSession()->GetDispatcher()->RegisterIdle(textPart, GetXMPFrame(), 15);
-
- this->SetDroppable(TRUE);
-
- fTextPart = textPart;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::~CTextFrame
- //----------------------------------------------------------------------------------------
-
- CTextFrame::~CTextFrame()
- {
- fTextPart->GetSession()->GetDispatcher()->UnregisterIdle(fTextPart, GetXMPFrame());
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::HandleKeyDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTextFrame::HandleKeyDown(XMPEventData event)
- {
- static CTextensionKeyCommand* lastCommand = NULL;
-
- CTextDrawInitiator di((CTextFacet *) GetActiveFacet());
-
- CTextension* text = fTextPart->GetEditText();
-
- fTextPart->SetEmbeddedRunFrame(this);
- fTextPart->SetEmbeddedRunFacet((CTextFacet *) GetActiveFacet());
-
- text->KeyDown(event);
-
- this->InvalidateAllFacets((CTextFacet *) GetActiveFacet(), NULL);
-
- GrowFrame();
-
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::DoIdle
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTextFrame::DoIdle()
- {
- CTextFacet* facet = (CTextFacet *) GetActiveFacet();
-
- if (facet)
- {
- CTextDrawInitiator di(facet);
-
- fTextPart->SetEmbeddedRunFrame(this);
- fTextPart->SetEmbeddedRunFacet((CTextFacet *) GetActiveFacet());
-
- (fTextPart->GetEditText())->Idle();
-
- return true;
- }
- else
- return false;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::FrameShapeChanged
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::FrameShapeChanged()
- {
- COpenDocText* textEdit = fTextPart->GetEditText();
- XMPFrame* xmpFrame = GetXMPFrame();
-
- xmpFrame->Invalidate(xmpFrame->GetUsedShape());
-
- FW_CEmbeddingFrame::FrameShapeChanged();
-
- FW_CRect frameRect;
- GetFrameShapeBounds(&frameRect);
-
- // ----- Set the new view rect size
-
- FW_SPlatformRect qdFrameRect = frameRect;
- textEdit->SetViewRect(&qdFrameRect);
-
- // ----- Set the frame size. This is similar to the dest rect in TE.
-
- frameRect.Inset(kBorderInset, kBorderInset);
-
- LongPoint frameSize(FixedToInt(frameRect.Width()), 0/*0 means unlimited hite*/);
-
- CFrames* frames = textEdit->GetFramesHandler();
-
- CDisplayChanges displayChanges;
- frames->SetTextFrameSize(&frameSize, &displayChanges);
-
- // ------ Reflow the text if necessary.
-
- short action = textEdit->DisplayChanged(&displayChanges);
-
- // ------ Notify embedded parts of position changes.
-
- textEdit->NotifyEmbeddedPartsOfPositionChange(0, textEdit->CountLines() - 1);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::FocusStateChanged
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::FocusStateChanged(XMPTypeToken focus, FW_Boolean newState)
- {
- FW_CEmbeddingFrame::FocusStateChanged(focus, newState);
-
- CTextDrawInitiator di((CTextFacet *) GetActiveFacet());
-
- if (focus == GetPart()->GetKeyFocusToken())
- {
- if (newState)
- {
- fTextPart->SetEmbeddedRunFrame(this);
- fTextPart->SetEmbeddedRunFacet((CTextFacet *) GetActiveFacet());
-
- (fTextPart->GetEditText())->Activate(true, true);
- ShowRuler();
- }
- else
- {
- fTextPart->SetEmbeddedRunFrame(this);
- fTextPart->SetEmbeddedRunFacet((CTextFacet *) GetActiveFacet());
-
- (fTextPart->GetEditText())->Activate(false, false);
- HideRuler();
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::NewFacet
- //----------------------------------------------------------------------------------------
-
- FW_CFacet* CTextFrame::NewFacet(XMPFacet* xmpFacet)
- {
- CTextFacet* facet = new CTextFacet;
- facet->InitTextFacet(xmpFacet, fTextPart);
- return facet;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::DoMenuEvent
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CTextFrame::DoMenuEvent(XMPMenuBar *menuBar, XMPCommandID command)
- {
- XMPMenuID menuId;
- XMPMenuItemID itemId;
-
- CTextDrawInitiator di((CTextFacet *) GetActiveFacet());
-
- menuBar->GetMenuAndItem(command, menuId, itemId);
- MenuHandle menu = menuBar->GetMenu(menuId);
-
- switch (menuId)
- {
- case CTextPart::kSizeMenu:
- fTextPart->SetEmbeddedRunFrame(this);
- fTextPart->SetEmbeddedRunFacet((CTextFacet *) GetActiveFacet());
- fTextPart->SetFontSize(gFontSizeTable[itemId - 1].fFontSize);
- break;
-
- case CTextPart::kFontMenu:
- {
- Str255 fontName;
-
- ::GetItem(menu, itemId, fontName);
- fTextPart->SetEmbeddedRunFrame(this);
- fTextPart->SetEmbeddedRunFacet((CTextFacet *) GetActiveFacet());
- fTextPart->SetFont(fontName);
- }
- break;
-
- default:
- return FW_CEmbeddingFrame::DoMenuEvent(menuBar, command);
- }
-
- return true;
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::FacetAdded
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::FacetAdded(FW_CFacet* facet)
- {
- FW_CEmbeddingFrame::FacetAdded(facet);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::FacetRemoved
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::FacetRemoved(FW_CFacet* facet)
- {
- FW_CEmbeddingFrame::FacetRemoved(facet);
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::ShowRuler
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::ShowRuler()
- {
- #ifdef NOT_WORKING
- if (this->GetXMPFrame()->IsRoot())
- return;
-
- XMPFrame* rootFrame = GetActiveFacet()->GetXMPWindow()->GetRootFrame();
- XMPFacet* rootFacet = GetActiveFacet()->GetXMPWindow()->GetRootFacet();
- XMPPart* rootPart = rootFrame->GetPart();
-
- FW_CRect rect;
- rootFrame->GetFrameShape()->GetBoundingBox(&rect);
- rect.right = IntToFixed(FixedToInt(rect.right) - 15);
- rect.bottom = IntToFixed(FixedToInt(rect.top)
- + CTextPart::kRulerRulerHeight
- + CTextPart::kRulerToolsHeight);
-
- XMPShape* newFrameShape = ::NewXMPShape(rect);
-
- fRulerFrame = rootPart->GetStorageUnit()->GetDraft()->
- CreateFrame(rootFrame, newFrameShape, fTextPart,
- fTextPart->GetSession()->Tokenize(kXMPViewAsFrame),
- fTextPart->GetRulerPresentation(),
- false, true);
-
- fRulerFrame = rootPart->RequestEmbeddedFrame(rootFrame,
- this->GetXMPFrame(),
- newFrameShape,
- fTextPart,
- fTextPart->GetSession()->Tokenize(kXMPViewAsFrame),
- fTextPart->GetRulerPresentation(),
- true);
-
- XMPShape* facetClip = ::NewXMPShape(fRulerFrame->GetFrameShape());
- FW_SPlatformPoint pt = { 0, 0 };
- XMPTransform* facetTransform = ::NewXMPTransform(pt);
- XMPFacet* rulerFacet
- = rootFacet->CreateEmbeddedFacet(fRulerFrame,
- facetClip,
- facetTransform,
- NULL, kXMPFrameInFront);
- fRulerFrame->Invalidate(NULL);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::HideRuler
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::HideRuler()
- {
- #ifdef NOT_WORKING
- if (this->GetXMPFrame()->IsRoot())
- return;
-
- fRulerFrame->Invalidate(NULL);
-
- XMPFrame* rootFrame = GetActiveFacet()->GetXMPWindow()->GetRootFrame();
- XMPFacet* rootFacet = GetActiveFacet()->GetXMPWindow()->GetRootFacet();
- XMPPart* rootPart = rootFrame->GetPart();
-
- XMPFacet* facet;
- BC_TDynamicCollection<XMPFacet *, BC_CUnmanaged> facets(4);
-
- XMPFrameFacetIterator it1(fRulerFrame);
- for (facet = it1.First(); it1.IsNotComplete(); facet = it1.Next())
- facets.Append(facet);
-
- BC_TCollectionActiveIterator<XMPFacet *> it2(facets);
- for (; !it2.IsDone(); it2.Next())
- {
- rootFacet->RemoveFacet(facet);
- delete facet;
- }
-
- rootPart->RemoveEmbeddedFrame(fRulerFrame);
-
- fRulerFrame = NULL;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CTextFrame::GrowFrame
- //----------------------------------------------------------------------------------------
-
- void CTextFrame::GrowFrame()
- {
- CTextension* textRecord = fTextPart->GetEditText();
- long textHeight = textRecord->GetTotalLinesHite();
-
- FW_CRect frameRect;
- GetFrameShapeBounds(&frameRect);
-
- if (textHeight > FixedToInt(frameRect.Height()) - 2 * kBorderInset)
- {
- // Calculate the new frame size and request the change.
-
- XMPShape* shape = new XMPShape();
-
- frameRect.bottom
- = ff(FixedToInt(frameRect.top) + kBorderInset + textHeight + kBorderInset);
- shape->SetRectangle(&frameRect);
- RequestFrameShape(shape);
- UpdateUsedAndActiveShapes();
-
- // Invalidate the entire frame. Should be smarter about this.
-
- Invalidate(shape);
-
- // ----- Set the new view rect size
-
- FW_SPlatformRect qdFrameRect;
- frameRect.AsPlatformRect(qdFrameRect);
- textRecord->SetViewRect(&qdFrameRect);
-
- // ----- Set the frame size. This is similar to the dest rect in TE.
-
- frameRect.Inset(kBorderInset, kBorderInset);
-
- LongPoint frameSize(FixedToInt(frameRect.Width()), 0/*0 means unlimited hite*/);
-
- CFrames* frames = textRecord->GetFramesHandler();
-
- CDisplayChanges displayChanges;
- frames->SetTextFrameSize(&frameSize, &displayChanges);
- }
- }
-
-